<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>字符串字母统计</title>
</head>

<body>
  <script>

    var str = "just for test!!!";
    function getCount(str) {
      var length = str.length;
      var res = {};
      for (let i = 0; i < length; i++) {
        if (str.charAt(i) == " ") continue;
        if (str.charAt(i) in res) res[str.charAt(i)]++;
        else res[str.charAt(i)] = 1;
      }
      return res;
    }

    console.log(getCount(str));

  </script>
</body>

</html>